<!--
 * Description: PBM报价修改组件
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/06/1 14:30
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="200px" :model="formData" size="mini">
      <el-row>
        <!--base Part Number-->
        <el-col :span="24">
          <el-form-item label="Part Number(Base)">
            <span :class="formData.basePartNo ? '' : 'null'">
              {{ formData.basePartNo || '暂无数据' }}
            </span>
          </el-form-item>
        </el-col>
        <!--base Part Name-->
        <el-col :span="24">
          <el-form-item label="Part Name(Base)">
            <span :class="formData.basePartName ? '' : 'null'">
              {{ formData.basePartName || '暂无数据' }}
            </span>
          </el-form-item>
        </el-col>
        <!--base qty -->
        <el-col :span="24">
          <el-form-item label="Qty(Base)">
            <span :class="formData.baseQty ? '' : 'null'">
              {{ formData.baseQty || '暂无数据' }}
            </span>
          </el-form-item>
        </el-col>
        <!--New Part Number-->
        <el-col :span="24">
          <el-form-item label="Part Number(New )">
            <span :class="formData.newPartNo ? '' : 'null'">
              {{ formData.newPartNo || '暂无数据' }}
            </span>
          </el-form-item>
        </el-col>
        <!--New Part Name-->
        <el-col :span="24">
          <el-form-item label="Part Name(New )">
            <span :class="formData.newPartName ? '' : 'null'">
              {{ formData.newPartName || '暂无数据' }}
            </span>
          </el-form-item>
        </el-col>

        <!--New qty -->
        <el-col :span="24">
          <el-form-item label="Qty(New )">
            <span :class="formData.newQty ? '' : 'null'">{{ formData.newQty || '暂无数据' }}</span>
          </el-form-item>
        </el-col>

        <!-- gcmTotalCostDelta-->
        <el-col :span="24">
          <el-form-item :label="$t('FdData.gcmTotalCostDelta')">
            <span :class="formData.gcmTotalCostDelta ? '' : 'null'">
              {{ formData.gcmTotalCostDelta || '暂无数据' }}
            </span>
          </el-form-item>
        </el-col>

        <!--pbmTotalCostDelta-->
        <el-col :span="24">
          <el-form-item :label="$t('FdData.pbmTotalCostDelta')">
            <el-input
              v-model="formData.pbmTotalCostDelta"
              v-precision:pbmTotalCostDelta.n0="formData"
              type="number"
            />
          </el-form-item>
        </el-col>

        <!-- pbmCommitTotalCostDelta-->
        <el-col :span="24">
          <el-form-item :label="$t('FdData.pbmCommitTotalCostDelta')">
            <el-input
              v-model="formData.pbmCommitTotalCostDelta"
              v-precision:pbmCommitTotalCostDelta="formData"
              type="number"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block;text-align: center;margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { fdFdQuote } from '@/api/quote/fd'

export default {
  name: 'FdQuoteEdit',
  props: {
    inputData: {
      type: Object,
      default() {
        return {}
      }
    },
    currentRowNo: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      // 正在查询
      isRequesting: false,
      formData: null
    }
  },

  created() {
    this.pageDataInit()
  },
  methods: {
    pageDataInit() {
      this.formData = this.$deepCopy(this.inputData)
    },
    async save() {
      try {
        this.isRequesting = true
        await fdFdQuote(
          {
            pbmTotalCostDelta: this.formData.pbmTotalCostDelta,
            pbmCommitTotalCostDelta: this.formData.pbmCommitTotalCostDelta,

            fdRowId: this.formData.fdRowId
          },
          { msgSuccess: true, msgError: true }
        )
        this.$emit('save', this.formData)
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form-item__content span {
  margin-left: 5px;
  color: blue;
}
.el-form-item__content .null {
  color: #ccc;
}
</style>
